<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class schedule extends CH_Controller{

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	 /**
         * Constructor
         */
	function __construct() { 
		parent::__construct(); 
		$this->init();
		$this->load->model(array('common_model','schedule_model','setting_model'));
		
    } 
    	
	/**
	 * 설교방송 목록
	 *
	 * @access	public
	 * @return	result
	 */
	function scheduleList(){
		login_admin();
		$url = $this->uri->segment(1).'/'.$this->uri->segment(2);
		$uri_array = segment_explode($this->uri->uri_string());
		$array_segment = array_keys($this->uri->segment_array(), "page");
		$param['yymm'] = in_array('yymm', $uri_array) ? urldecode($this->security->xss_clean(url_explode($uri_array, 'yymm'))) : date("Y-m");
		$uri_segment = in_array('page', $uri_array) ? $array_segment[0]+1 : 0;
		
		$result = $this->schedule_model->schedule_list($param);
		$_schedule = null;
		foreach($result as $row){
			$_schedule[] = array('id'=>$row->id,'date'=>substr($row->schedule_date,0,10),'time'=>$row->schedule_time,'title'=>$row->title,'content'=>$row->content);
		}
	
		$data = array(
				'_title' => '행사관리',
				'_group' => 'homepage',
				'_content' => $this->config->item('ch_manager_root').'/'.$url,
				'_schedule' => $_schedule,
 				'param'=>$param
				
		);
		return $data ;
	}
	
	/**
	 * 설교방송 폼
	 *
	 * @access	public
	 * @return	result
	 */
	function scheduleForm(){
		login_admin();
		$uri_array = segment_explode($this->uri->uri_string());
		$page = in_array('page', $uri_array) ? urldecode($this->security->xss_clean(url_explode($uri_array, 'page'))) : 1;
		$schedule_id = in_array('id', $uri_array) ? urldecode($this->security->xss_clean(url_explode($uri_array, 'id'))) : null;
		$url = $this->uri->segment(1).'/'.$this->uri->segment(2);
				
		$data = array(
				'_title' => '행사관리',
				'_group' => 'homepage',
				'_content' => $this->config->item('ch_manager_root').'/'.$url,
				
		);

		$data = array_merge($data,array('code_duty'=> $this->common_model->select_child_code(2),'code_title'=> $this->common_model->select_child_code(3)),$this->schedule_model->select($schedule_id));
		return $data ;
	}
	
	/**
	 * 설교방송 db 처리
	 *
	 * @access	public
	 * @return	void
	 */
	function scheduleDbjob(){
		$dbjob = $this->input->post('dbjob');
		$id = $this->input->post('id');
		$content = $this->input->post('content');
		$title = $this->input->post('title');
		$yymm = substr($this->input->post('schedule_date'),0,7);
		if(!get_magic_quotes_gpc()){
			$content = addslashes($content);
			$title = addslashes($title);
		}
		
		switch($dbjob){
			case('i'):
				$msg = '저장되었습니다.';
				$data = array(
						'title' => $title ,
						'schedule_date' => $this->input->post('schedule_date') ,
						'schedule_time' => $this->input->post('schedule_time') ,
						'content' => $content
				);
			break;
			case('u'):
				$msg = '수정되었습니다.';
				$data = array(
						'title' => $title ,
						'schedule_date' => $this->input->post('schedule_date') ,
						'schedule_time' => $this->input->post('schedule_time') ,
						'content' => $content
				);
			break;
			case('d'):
				$msg = '삭제 되었습니다.';
				$data = array('id' => $id);
			break;
		}
		
		$this->schedule_model->dbjob($data);
		$this->alert->jalert($msg, base_url('/schedule/scheduleList/yymm/'.$yymm));
	}
	
	
	function ajax_get_schedule(){
		$url = $this->uri_church();
		$id = $this->input->get('id');
		$data = array(
				'_title' => '행사관리',
				'_group' => 'homepage',
				'_content' => $this->config->item('ch_manager_root').'/'.$url
		);
		$data = array_merge($data,$this->schedule_model->select($id));
		return $data;
	}
	
}

/* End of file html.php */
/* Location: ./application/controllers/member.php */